package com.cosina.game.crystallight.ui.monster;

import com.cosina.game.crystallight.util.World;

import android.graphics.Bitmap;

public class MonsterFrames {
	private final Bitmap[] bitmaps;
	public final int xspan,yspan;
	public final boolean directionWill;
	public int cycle;
	public MonsterFrames(Bitmap[] bitmaps,int xspan, int yspan){
		this.bitmaps = bitmaps;
		directionWill = bitmaps.length % 4 == 0;
		if(directionWill){
			this.cycle = bitmaps.length/4;
		}
		
		this.xspan = xspan;
		this.yspan = yspan;
	}
	
	public Bitmap getFrame(int direction,int frame){
		if(directionWill == false)
			return bitmaps[frame];
		// y x z s
		switch (direction) {
		case World.RIGHT:
			return bitmaps[frame];
		case World.BOTTOM:
			int index = frame + cycle;
			if(index < bitmaps.length)
				return bitmaps[index];
			else
				break;
		case World.LEFT:{
			index = frame + cycle * 2;
			if(index < bitmaps.length)
				return bitmaps[index];
			else
				break;
		}
		case World.TOP:
			index = frame + cycle * 3;
			if(index < bitmaps.length)
				return bitmaps[index];
			else
				break;
		}
		return bitmaps[frame];
	}
}
